/**
 * Created by IntelliJ IDEA.
 * User: gongwenwei
 * Date: 12-1-30
 * Time: 上午10:18
 * To change this template use File | Settings | File Templates.
 */

object FileMatcher {
  private def filesHere = (new java.io.File(".")).listFiles
  def filesEnding(query: String) =
    for (file <-filesHere;if file.getName.endsWith(query))
      yield file

  def filesContaining(query: String) =
    for (file <-filesHere;if file.getName.contains(query))
      yield file

  def filesRegex(query: String) =
    for (file <-filesHere;if file.getName.matches(query))
      yield file

  def filesMatching(matcher:String => Boolean) =
    for (file <-filesHere;if matcher(file.getName))
       yield file

  def filesEnding1(query: String) =
    filesMatching(_.endsWith(query))

  def filesContaining1(query: String) =
    filesMatching(_.contains(query))

  def filesRegex1(query: String) =
    filesMatching(_.matches(query))
}